home *** CD-ROM | disk | FTP | other *** search
/ Developer Helper 1: Phil & Dave's Excellent CD / Excellent CD HFS.raw / Moof / Goodies / MPW Goodies / MPW Goodies⁄DTS / Srcs / OSErr Source / OSErr.c next >
C/C++ Source or Header  |  2022-08-05  |  2KB  |  96 lines

  1. #include <StdDef.h>
  2. #include <StdLib.h>
  3. #include <StdIO.h>
  4.  
  5. #include <Resources.h>
  6. #include    <ToolUtils.h>
  7.  
  8. #define    begin        {
  9. #define    end        }
  10.  
  11.  
  12. typedef struct {
  13.     short int    LowBounds;
  14.     short int    ResNum;
  15. } errRef;
  16.  
  17. typedef struct {
  18.     short int    ItemCount;
  19.     errRef        Items[1];
  20. } elut, *elutPtr, **elutHdl;
  21.  
  22.  
  23. /*----------------------------------------*/
  24. /* reportFailure                                    */
  25. /* Tell user of error in OSerr and abort.    */
  26. /*----------------------------------------*/
  27. void reportFailure(char *message, char *miscInfo)
  28.     begin
  29.         fprintf(stderr,"### OSErr: %s\n",message,miscInfo);
  30.         exit(1);
  31.     end
  32.  
  33.  
  34. /*----------------------------------------*/
  35. /* doMsg                                        */
  36. /* Write MacOS meaning to StdOut                */ 
  37. /*----------------------------------------*/
  38. void doMsg(int errNum, int resNum, int indexNum)
  39.     begin
  40.         char    message[256];
  41.         
  42.         GetIndString(message,resNum,indexNum);
  43.         printf("OSERR %d: %P\n", errNum, (message[0]) ? message : "\pNo such message");
  44.     end /* doMsg */
  45.     
  46.  
  47. /*----------------------------------------*/
  48. /* main                                                */
  49. /*----------------------------------------*/
  50. int main(int argc, char **argv)
  51.     begin
  52.         elutHdl    theTable;
  53.         int        i;
  54.         int        j;
  55.         int        errNum;
  56.         int        bounds;
  57.         
  58.         //
  59.         //--- See if the user typed any arguments
  60.         //
  61.         if (argc<2)
  62.             reportFailure("Usage… OSERR [error number]", NULL);
  63.         
  64.         //
  65.         //--- Read the table that will tell us what STR# resource the message is in
  66.         //
  67.         theTable    = (elutHdl )GetResource( (ResType)'eLUt',127);
  68.         if (!theTable)
  69.             reportFailure("Can't load 'eLUt' resource.", NULL);
  70.     
  71.     
  72.         //
  73.         //--- Main loop
  74.         //
  75.         for(i=1; i<argc; i++)
  76.             begin
  77.                 errNum    = atoi(argv[i]);
  78.                 if (errNum >= 0)
  79.                     reportFailure("Error number must be negative. (%s)", argv[i]);
  80.                 
  81.                 errNum    = (-errNum);
  82.                     
  83.                 for(j=0; j<(**theTable).ItemCount; j++)
  84.                     begin
  85.                         bounds    = (**theTable).Items[j].LowBounds;
  86.                         if ((errNum >= bounds) && (errNum <= (bounds+100)))
  87.                             doMsg(errNum,(**theTable).Items[j].ResNum,errNum-bounds+1); 
  88.                     end /* for */
  89.                     
  90.             end /* for */
  91.         
  92.         return 0;
  93.  
  94.     end /* main */
  95.  
  96.